package com.orange.adminapi.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.user.UserCoupon;
import com.orange.core.pojo.req.usercoupon.UserCouponPageReq;
import com.orange.core.pojo.req.usercoupon.UserCouponRefundAuditReq;
import com.orange.core.service.user.UserCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户优惠券
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/userCoupon")
public class UserCouponController {

    private final UserCouponService userCouponService;

    /**
     * 列表
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).USER_COUPON_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<UserCoupon>> page(@RequestBody PageReqDto<UserCouponPageReq> req) {
        return R.ok(userCouponService.page(req));
    }

    /**
     * 导出
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).USER_COUPON_EXPORT.permission.identifier)")
    @PostMapping("/export")
    public void export(@RequestBody UserCouponPageReq condition, HttpServletResponse response) {
        userCouponService.export(condition, response);
    }

    /**
     * 退款审核
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).USER_COUPON_REFUND_AUDIT.permission.identifier)")
    @PostMapping("/refund/audit")
    public R<Boolean> auditRefund(@RequestBody UserCouponRefundAuditReq req) {
        userCouponService.auditRefund(req);
        return R.ok(true);
    }
}
